import { Component } from '@angular/core';
import { 
  Platform, 
  Events, 
  AlertController, 
  App,
  List, 
  ModalController, 
  NavParams, 
  NavController, 
  LoadingController,
  ActionSheetController } from 'ionic-angular';
import { InfoCollectService } from './detail.service';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
import { Config } from '../../../../../providers/config';
import { Common } from '../../../../../providers/common';
import { Storage } from '@ionic/storage';
// pdf容器
import { PdfViewerComponent } from 'ng2-pdf-viewer';
import _ from 'lodash';

@Component({
  selector: 'page-irp-report-collect-detail',
  templateUrl: './detail.html',
  providers: [InfoCollectService]
})
export class IrpReportCollectDetailPage {
  // 用户logonname
  public logonname:any;
  // 用户orgid
  public orgid:any= [];
  // 报告信息
  public info:any ;
  // 报告ID
  public reportid: any;
  // 评论框状态
  public isCommentStatus= false;
  // 评论内容
  public commentContent:any;
  // 评论列表
  public CommentList:any = [];

constructor(
  public alertCtrl: AlertController,
  public app: App,
  public modalCtrl: ModalController,
  public navCtrl: NavController,
  public config: Config,
  private sanitizer: DomSanitizer,
  public events: Events,
  public storage: Storage,
  private common: Common,
  private actionSheetCtrl: ActionSheetController,
  private navParams: NavParams,
  public loadingCtrl: LoadingController,
  public collectService:InfoCollectService 
) {
  // 清空上次数据
  //this.info = null;
  //this.CommentList = [];
  // 获取传入报告信息
  this.info = this.navParams.data;
  // 获取报告id
  this.reportid = this.info.objid;
  // 获取用户登录名
  this.logonname = sessionStorage.getItem('logonname');
  // 获取用户orgid
  this.getOrgid(this.logonname);
  // 获取评论列表
  this.getIrmReportComment(this.reportid);
  console.log("用户登录名 = "+this.logonname);
  console.log("报告信息 = "+JSON.stringify(this.info));
}

  // 获取登录人orgid
  getOrgid(logonname){
    let that = this;
    this.collectService.getOrgid(logonname).subscribe(data=> {
      if (data) {
        that.orgid = data[0].orgid;
      }
    })
  }
  // 获取评论
  getIrmReportComment(reportid){
    let that = this;
    this.collectService.getIrmReportComment(reportid).subscribe(data=> {
      if (data) {
        that.CommentList = _.pull(data,null);
      }
    })
  }
  // 发送评论
  sendComment(){
    let that = this;
    this.commentContent = document.getElementById("areatext-content").innerHTML + "";
    this.collectService.sendIrmReportComment(that.orgid,that.reportid,this.commentContent).subscribe(data=>{
      if(data){

      }
    });
    // 刷新评论内容
    that.getIrmReportComment(that.reportid);
  }
  // 评论框状态
  toggleComment(status){
    if(status=='start'){
      this.isCommentStatus = true;
    }
    if(status=='end'){
      this.isCommentStatus = false;
    }
  }
  // 分享模块
  shareModel(){
    let actionSheet = this.actionSheetCtrl.create({
      buttons: [
        {
          text: '微信分享',
          handler: () => {
          }
        },
        {
          text: '微信分享朋友圈',
          handler: () => {
          }
        },
        {
          text: '取消分享',
          role: 'cancel',
          handler: () => {
          }
        }
      ]
    });
    actionSheet.present();
  }
}
